# bkp-ctf-2016 bob's hat (layer 2)

import fractions
import sys

if len(sys.argv) != 3:
  print 'usage: %s 0x86E996013E77C41699000E0941D480C046B2F71A4F95B350AC1A4D426372923D8A4561D96FBFB0240595907201AD3225CF6EDED7DE02D91C386FFAC280B72D0F95CAE71F42EBE0D3EDAEACE7CEA3195FA32C1C6080D90EF853D06DD4572C92B9F8310BBC0C635A5E26952511751030A6590816554E763031BCBB31E3F119C65F 0xABE633CEC2E7EC10A851927905A657DF4E10416023C0C34FC64D64BD8B8257B7BF207ADD047B0ADF21C525B052068C70295C746C3B1BE1436F39ED8BF7A813E4B845CE0CA89CA828B45763D46B1898C7A2FA5F8FE78428CAB6CDF70EF871DB971B3232841A1CE2459CE650A154362F80CFB64163C3CA63AD72BCFBDBF0154FF7' % sys.argv[0]
  exit(2)

n1 = int(sys.argv[1], 16)
n2 = int(sys.argv[2], 16)

p = fractions.gcd(n1, n2) # or q but it doesnt matter
q = (n2 / p)

print 'found common factor'
print 'p = %d' % p
print 'q = %d' % q
print '''generate private key with:
python ~/tools/crypto/rsatool/rsatool.py -p %s -q %s -o /tmp/privkey.pem''' % (p, q)

